package com.blq.developtools.view.viewholder;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.blq.developtools.R;
import com.blq.developtools.bean.LayoutInspectorBean;

/**
 * <pre>
 * ****************************************************************
 * 文件名称:LayoutInspectorViewHolder.java
 * 作 者:SSNB
 * 创建时间:2024/5/21
 * 文件描述:
 * 注意事项:
 * 版权声明:Copyright (C) 2015-2025 杭州中焯信息技术股份有限公司
 * 修改历史:2024/5/21 1.00 初始版本
 * ****************************************************************
 * </pre>
 */
public class LayoutInspectorViewHolder extends TemplateViewHolder<LayoutInspectorBean> {
    //    private FloatWindowHelper floatWindowHelper;
    private TextView currentAppNameView;
    private View smallScanBtn;
    private View closeBtn;
    private View appInfoBtn;
    private View infoRootView;

    private TextView packageNameView;
    private TextView activityNameView;
    private View largerScanBtn;
    private View downloadLayoutBtn;

    private OnActionClickListener actionClickListener;

    public LayoutInspectorViewHolder(Context context) {
        this(context, R.layout.float_layout_view);
    }

    public LayoutInspectorViewHolder(Context context, int layoutID) {
        super(context, layoutID);
    }

    public LayoutInspectorViewHolder(View rootView) {
        super(rootView);
    }

    @Override
    protected void initView(View rootView) {
        currentAppNameView = rootView.findViewById(R.id.tv_show_app_name);
        smallScanBtn = rootView.findViewById(R.id.btn_scan_layout_small);
        closeBtn = rootView.findViewById(R.id.btn_properties_close);
        appInfoBtn = rootView.findViewById(R.id.btn_app_info);

        infoRootView = rootView.findViewById(R.id.cl_info_expand_view);
        packageNameView = rootView.findViewById(R.id.tv_package_name_value);
        activityNameView = rootView.findViewById(R.id.tv_activity_name_value);
        largerScanBtn = rootView.findViewById(R.id.btn_scan_layout_larger);
        downloadLayoutBtn = rootView.findViewById(R.id.btn_download_layout);

        bindEvent();
    }

    @Override
    protected void bindEvent() {
        closeBtn.setOnClickListener(v -> {
            if (actionClickListener != null) {
                actionClickListener.onCloseClick();
            }
        });
        appInfoBtn.setOnClickListener(v -> {
            if (actionClickListener != null) {
                actionClickListener.onAppInfoClick();
            }
        });


        smallScanBtn.setOnClickListener(v -> {
            if (actionClickListener != null) {
                actionClickListener.onLayoutScanClick();
            }
        });
        largerScanBtn.setOnClickListener(v -> {
            if (actionClickListener != null) {
                actionClickListener.onLayoutScanClick();
            }
        });

        downloadLayoutBtn.setOnClickListener(v -> {

        });

    }

    @Override
    protected void onBindData(LayoutInspectorBean data) {
        currentAppNameView.setText(String.format("查看[%s]布局", data.getAppName()));
        infoRootView.setVisibility(data.isSmall() ? View.GONE : View.VISIBLE);
        smallScanBtn.setVisibility(data.isSmall() ? View.VISIBLE : View.GONE);
        packageNameView.setText(data.getPackageName());
        activityNameView.setText(data.getClassName());

    }

    public void setActionClickListener(OnActionClickListener actionClickListener) {
        this.actionClickListener = actionClickListener;
    }

    public interface OnActionClickListener {
        void onCloseClick();

        void onLayoutScanClick();

        void onAppInfoClick();
    }

}
